<?php
/**
 * Nusoap服务
 * @author Administrator
 *
 */
class nusoapServer extends Controller{
    //var $server = null;//服务
    //构造函数
    function nusoapServer(){
        parent::Controller();
        
        $this->load->library('Nusoap');
        $this->server = new soap_server();
        //避免乱码
        $this->server->soap_defencoding = 'UTF-8';
        $this->server->decode_utf8      = false;
        $this->server->xml_encoding     = 'UTF-8';
        $this->server->configureWSDL('test');//打开 wsdl 支持
    }
    /**
     * 服务
     * @return string
     */
    function index(){
        /**
         * 供调用的方法
         * @param unknown $name
         * @return string
         */
        /*
         * 注册需要被客户端访问的程序 
         * 类型对应值：
         * bool->"xsd:boolean"
         * string->"xsd:string"
         * int->"xsd:int"
         * float->"xsd:float" 
         */
        $this->server->register('GetTestStr',//方法名
            array('name'=>'xsd:string'),
            array('return'=>'xsd:string')
            );
        /* if (isset($_GET['wsdl'])){
            $_SERVER['QUERY_STRING'] = 'wsdl';
        }else{
            $_SERVER['QUERY_STRING'] = '';
        } */
        if($this->uri->segment(3) == "wsdl"){ 
            $_SERVER['QUERY_STRING'] = "wsdl"; 
        }else{ 
            $_SERVER['QUERY_STRING'] = ""; 
        }
        //isset  检测变量是否设置  
        $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
        $HTTP_RAW_POST_DATA = $GLOBALS['HTTP_RAW_POST_DATA'];
        //$HTTP_RAW_POST_DATA = isset ($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';  
        //service  处理客户端输入的数据  
        $this->server->service($HTTP_RAW_POST_DATA);
    }
}

function GetTestStr($name){
    return "Hello, 你在哪里{ $name }!";
}